package jiang.web.controller.dataCollection;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpSession;

import jiang.app.service.HeadhunterService;
import jiang.app.service.RecommendService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class HeadhunterController {

	@Autowired
	RecommendService recommendService;
	@Autowired
	HeadhunterService headhunterService;

	@RequestMapping(value = "/manage/dataCollection/headhunter", method = RequestMethod.GET)
	public String headhunter() {
		return "dataCollection/headhunter/index";
	}

	@RequestMapping(value = "/manage/dataCollection/headhunter", method = RequestMethod.POST)
	public String headhunter2(MultipartFile excel, HttpSession s, Model m)
			throws Exception, IOException {
		File f = new File(s.getServletContext().getRealPath("/temp")); // 临时文件
		excel.transferTo(f);
		boolean success = headhunterService.saveCandidate(f);
		if (success) {
			m.addAttribute("tip", "提交成功");
		}
		else {
			m.addAttribute("tip", "提交失败");
		}
		return "dataCollection/headhunter/result";
	}
}
